<?php

/**
 * Description of Exposure_orderController
 *
 * @author wml
 */

namespace Home\Controller;

use Think\Controller;

class CompanyCertificatController extends CommonController {
    
    
    public function companyInfo() {
        $companyModel = D("company_certificat");
        if (IS_POST) {
            //审核已过的信息无法修改    
            if (intval(I("post.id"))) {
                $companyInfo = $companyModel->getDataById("id=" . intval(I("post.id")), "id,status");
                if ($companyInfo['status'] == 1) {
                    $arr['status'] = 100;
                    $arr['info'] = "只有未审核信息才能修改";
                    $this->ajaxReturn($arr);
                    exit;
                }
            }
            $result = $companyModel->editData(I("post."));
            if (!$result) {
                $arr['status'] = 100;
                $arr['info'] = $companyModel->getError();
            } else {
                $arr['status'] = 200;
                $arr['info'] = "提交成功";
            }
            $this->ajaxReturn($arr);
        } else {
            $companyInfo = $companyModel->getDataById("user_id=" . session("user.id"));
            $this->assign("companyInfo", $companyInfo);
            $this->display();
        }
    }
    /*
     * 身份证和营业执照图片上传
     * csb
     */
    public function certificatesInfo() {
        if (IS_POST) {
            if ($_FILES['business_img']['name'] == "" || $_FILES['id_is_img']['name'] == "" || $_FILES['id_the_img']['name'] == "" || $_FILES['id_hold']['name'] == "") {
                $this->error("请上传完整的信息");
                exit;
            }
            $companyModel = D("company_certificat");
            $companyInfo = $companyModel->getDataById("user_id=" . session("user.id"));
            if (count($companyInfo) < 1) {
                $this->error("请先提交公司信息");
                exit;
            } 
            $companyInfo["__hash__"] = I('post.__hash__');
            $result = $companyModel->uploadCertificates($companyInfo);
            if (!$result) {
                $this->error($companyModel->getError());
            } else {
                $this->success("提交成功");
            }
        } else {
            $companyModel = D("company_certificat");
            $companyInfo = $companyModel->getDataById("user_id=" . session("user.id"), "business_img,id_is_img,id_the_img,id_hold,status,feedback");
            $this->assign("companyInfo", $companyInfo);
            $this->display();
        }
    }
}

?>
